package org.ftz.JudgeOnline.CPP;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
class transferExe {
    public static void main(String[] args) {
        String cmd = "cmd /c D:\\BigProgram\\test.exe" + " < D:\\BigProgram\\test.txt > D:\\BigProgram\\out.txt"; //调用的exe可执行文件（ps: 调用可执行文件和参数拼接必须要用空格隔开）
        openExe(cmd);
    }
    public static void openExe(String cmd) {
        BufferedReader br = null;
        BufferedReader brError = null;
        try {
            Process p = Runtime.getRuntime().exec(cmd); //执行exe  cmd可以为字符串(exe存放路径)也可为数组，调用exe时需要传入参数时，可以传数组调用(参数有顺序要求)
            String line = null;
            InputStream inputStream = p.getInputStream(); //获得子进程的输入流。
            InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
            br = new BufferedReader(inputStreamReader);
            InputStream errorStream = p.getErrorStream();  //获得子进程的错误流。
            InputStreamReader inputStreamReader1 = new InputStreamReader(errorStream);
            brError = new BufferedReader(inputStreamReader1);
            while ((line = br.readLine()) != null  || (line = brError.readLine()) != null) {
                System.out.println(line);  //输出exe输出的信息以及错误信息
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}